wmf.data.mmManageUrl = 'http://localhost:8080/rs/';

/*
Ext.Ajax.on('requestexception', function(conn,response,options) {
	if(typeof response.getResponseHeader == 'undefined' || typeof response.getResponseHeader.wmfack == 'undefined' ||
			response.getResponseHeader.wmfack == 'ok' &&
			response.getResponseHeader.sessionstatus == 'timeout') {
		
		window.location.href = "logout.jsp";							
	}
});
*/

wmf.data.mydateformat = wmf.data.mydateformat || function(value){
	if(!value) return value;
	var time = new Date(parseInt(value));
	var year=(time.getYear() < 1900) ? (1900 + time.getYear()) : time.getYear();    
    var month=time.getMonth()+1;     
    var date=time.getDate();     
    var hour=time.getHours();     
    var minute=time.getMinutes();     
    var second=time.getSeconds();     
    return year+"-"+(month<10?"0":"")+month+"-"+(date<10?"0":"")+date+" "+(hour<10?"0":"")+hour+":"+(minute<10?"0":"")+minute+":"+(second<10?"0":"")+second; 
};

wmf.data.loadAction =  wmf.data.loadAction || function(resourceid, list, text){
	Ext.Ajax.request({
		url:'action/loadActions.do',
		params: {
			resourceid: resourceid,
			ownertype: 2
		},
		success : function(respond, opts) {
			var responds = Ext.decode(respond.responseText);
			if(responds.failure){
				Ext.Msg.alert('提示', responds.msg?responds.msg: '操作错误');
				return false;
			}
			var data = [];
			for(var i = 0; i < responds.length; i++){
				data.push({
					text: responds[i].name,
					itemId: responds[i].handler,
					icon: 'resources/icons/'+responds[i].icon+'.png'
				});
				data.push({
					xtype: 'tbseparator'
				});
			}
			if(text){
				data.push(text);
			}
			list.dockedItems.items[1].removeAll();
			list.dockedItems.items[1].add(data);
		},
		failure : function(respond, action) {
			Ext.Msg.alert("提示", "操作错误");
		}
	});
},

wmf.data.filterQuery = wmf.data.filterQuery || function(e){
	var combo = e.combo;
	if(!e.forceAll){  
		var value = e.query;
	    if(value){
    	    combo.store.filter({
        		property     : combo.displayField,
        		value        : value,
        		anyMatch     : true, //optional, defaults to true
        		caseSensitive: false  //optional, defaults to true
        	});  
    	    combo.onLoad();
	    }else{
	    	combo.store.clearFilter();
	    }
	}else{
		combo.selectedIndex = -1;
		combo.store.clearFilter();
        combo.onLoad();
	}
	return false;
};

wmf.data.changeTimeType = wmf.data.changeTimeType || function(time){
	var respond = time.split("-");
	if(!respond || respond.length != 3)
		return time;
	return respond[0] + respond[1] + respond[2];
};

//根据容器大小按比例调整图片大小
function AutoResize(myWidth, myHeight, standardWidth, standardHeight) {
	this.defaultWidth = standardWidth;
	this.defaultHeight = standardHeight;
	this.width = myWidth;
	this.height = myHeight;
	this.aWidth = 0;
	this.aHeight = 0;
	
	var needResize = false;
	if (myWidth > standardWidth) {
		needResize = true;
	} else {
		if (myHeight > standardHeight) {
			needResize = true;
		}
	}
	
	if (needResize) {
		var tempHeight = parseInt((this.defaultWidth * myHeight)/myWidth);
		if (tempHeight < this.defaultHeight) {
			this.aWidth = this.defaultWidth;
			this.aHeight = tempHeight;
		} else {
			var tempWidth = parseInt((this.defaultHeight * myWidth)/myHeight);
			this.aWidth = tempWidth;
			this.aHeight = this.defaultHeight;
		}
	}
	
	this.getWidth = function() {
		if (needResize) {
			return this.aWidth;
		} else {
			return this.width;
		}
	}
	this.getHeight = function() {
		if (needResize) {
			return this.aHeight;
		} else {
			return this.height;
		}
	}
}